import React,{ lazy,Suspense } from 'react';
// lazy 是一个方法，引入组件的方法，函数以懒加载的形式引入
// Suspense 是一个组件，可以指定加载组件时的动画
import { Route,Redirect,Switch } from 'react-router-dom';

import Loading from '@/components/Loading';

const Login = lazy(() => import('@/views/login/Index'))
const Dashbiard = lazy(() => import('@/views/dashboard/Dashboard'))
const Index = () => {
	return (
		// fallback 加载回调  Suspense 作用当路山匹配的组件还没有显示之前，显示 Loading 组件
		<Suspense fallback={ <Loading></Loading> }>
			<Switch>
				<Route path='/login' component={ Login }></Route>
				<Route path='/dashboard' component={ Dashbiard }></Route>
				<Redirect from='/' to='/login' exact></Redirect>
			</Switch>
		</Suspense>
	);
}

export default Index;
